package com.itheima.consumer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitFanoutConfig {

    // 定义第一个队列
    @Bean
    public Queue queue1() {
        return new Queue("queue1", true); // 'true' for durable queue
    }

    // 定义第二个队列
    @Bean
    public Queue queue2() {
        return new Queue("queue2", true);
    }

    // 定义fanout类型的交换机
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange("myFanoutExchange");
    }

    // 将queue1绑定到fanout交换机上
    @Bean
    public Binding binding1(Queue queue1, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue1).to(fanoutExchange);
    }

    // 将queue2绑定到fanout交换机上
    @Bean
    public Binding binding2(Queue queue2, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(queue2).to(fanoutExchange);
    }
}
